﻿using System;
using System.Text;
using System.IO;

namespace ooWii.IO
{
	public class GCFileInfo
	{
		#region GCFileInfo

		string name;
		Stream partition;
		long fileOffset;
		UInt32 fileSize;
		GCDirectoryInfo directoryInfo;

		public GCFileInfo( Stream partition, GCDirectoryInfo directoryInfo, string name, long fileOffset, UInt32 fileSize )
		{
			this.partition = partition;
			this.directoryInfo = directoryInfo;
			this.name = name;
			this.fileOffset = fileOffset;
			this.fileSize = fileSize;
		}

		public string Name
		{
			get
			{
				return name;
			}
		}

		public Stream OpenRead()
		{
			SparseStream stream = new SparseStream( partition );
			stream.Map( 0, fileOffset, fileSize );
			stream.SetLength( fileSize );
			return stream;
		}

		public string FullName
		{
			get
			{
				StringBuilder stringBuilder = directoryInfo.BuildPath();
				stringBuilder.Append( "/" );
				stringBuilder.Append( name );
				return stringBuilder.ToString();
			}
		}

		#endregion
	}
}
